home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / Kibitz / SaveBoardImage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-02  |  2.6 KB  |  131 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        saveboardimage.c
  5. ** Writtem by:  Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __ERRORS__
  21. #include <Errors.h>
  22. #endif
  23.  
  24. #ifndef __UTILITIES__
  25. #include <Utilities.h>
  26. #endif
  27.  
  28.  
  29.  
  30. /*****************************************************************************/
  31.  
  32.  
  33. #ifdef powerc
  34. #pragma options align=mac68k
  35. #endif
  36. typedef struct TMDHdr {
  37.     OSType    fType;
  38.     short    hdrID;
  39.     short    version;
  40.     short    prRec[60];
  41.     Fixed    xOrigin;
  42.     Fixed    yOrigin;
  43.     Point    xScale;
  44.     Point    yScale;
  45.     short    atrState[31];
  46.     short    lCnt;
  47.     short    lTot;
  48.     long    lSiz;
  49.     Rect    lR2D;
  50.     short    filler1[145];
  51. } TMDhdr;
  52. #ifdef powerc
  53. #pragma options align=reset
  54. #endif
  55.  
  56. static TMDhdr    boardHeader = {
  57.     'PICT',
  58.     0x0000        /* NOT MacDraw II specific data.  Just simple PICT. */
  59. };
  60.  
  61. extern short    gPrintPage;
  62.  
  63.  
  64.  
  65. /*****************************************************************************/
  66.  
  67.  
  68.  
  69. #pragma segment File
  70. OSErr    SaveBoardImage(FileRecHndl frHndl)
  71. {
  72.     StandardFileReply    reply;
  73.     FInfo                finfo;
  74.     WindowPtr            oldPort;
  75.     Rect                boardRect;
  76.     short                fileRefNum;
  77.     PicHandle            boardImage;
  78.     long                count;
  79.     OSErr                err;
  80.  
  81.     reply.sfFile.name[0] = 0;
  82.     if (!DisplayPutFile(&reply)) return(userCanceledErr);        /* User canceled the save. */
  83.  
  84.     err = Create_OpenFile(&reply.sfFile, &fileRefNum, 'PICT');
  85.     if (err) return(err);        /* Oops. */
  86.  
  87.     HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, &finfo);
  88.     finfo.fdCreator = 'ttxt';
  89.     HSetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, &finfo);
  90.  
  91.     oldPort = SetFilePort(frHndl);
  92.  
  93.     boardRect = BoardRect();
  94.     InsetRect(&boardRect, -1, -1);
  95.     boardImage = OpenPicture(&boardRect);
  96.     if (!boardImage) {
  97.         SetPort(oldPort);
  98.         return(memFullErr);
  99.     }
  100.  
  101.     ImageBoardLines(1, kBoardHOffset, kBoardVOffset);
  102.     gPrintPage = -1;
  103.     ImageDocument(frHndl, true);
  104.     gPrintPage = 0;
  105.  
  106.     ClosePicture();
  107.  
  108.     err = SetFPos(fileRefNum, fsFromStart, 0);
  109.         /* Set the file position to the beginning of the file. */
  110.  
  111.     if (!err) {
  112.         count = sizeof(TMDhdr);
  113.         err   = FSWrite(fileRefNum, &count, (Ptr)&boardHeader);
  114.     }
  115.  
  116.     if (!err) {
  117.         HLock((Handle)boardImage);
  118.         count = GetHandleSize((Handle)boardImage);
  119.         err   = FSWrite(fileRefNum, &count, (Ptr)*boardImage);
  120.     }
  121.     KillPicture(boardImage);
  122.  
  123.     FSClose(fileRefNum);
  124.     SetPort(oldPort);
  125.  
  126.     return(err);
  127. }
  128.  
  129.  
  130.  
  131.